package cn.itripsearch.controller;


import cn.itrip.beans.dtos.Dto;
import cn.itrip.beans.dtos.InputDto;
import cn.itrip.beans.vo.search.ItripHotelPage;
import cn.itrip.beans.vo.search.ListItripHotelPage;
import cn.itrip.beans.vo.search.listItripHotelListByHotCity;
import cn.itrip.common.EmptyUtils;
import cn.itrip.common.Pages;
import cn.itripsearch.beans.vo.ItripHotelVO;
import cn.itripsearch.beans.vo.SearchHotCityVO;
import cn.itripsearch.beans.vo.SearchHotelVO;
import cn.itripsearch.service.IItripHotelService;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/search/api/hotellist")
public class ItripHotelController {
    @Resource
    IItripHotelService iItripHotelService;


    @PostMapping("/searchItripHotelListByHotCity")
    public Dto <Pages<ItripHotelVO>> searchItripHotelListByHotCity(@RequestBody SearchHotCityVO vo)throws  Exception{
        if (EmptyUtils.isEmpty(vo)||EmptyUtils.isEmpty(vo.getCityId())){
            return InputDto.error("失败");
        }
        Map<String,Object> map=new HashMap<>();
        map.put("cityId",vo.getCityId());
        List<ItripHotelVO> list=iItripHotelService.searchItripHotelListByCityId(vo.getCityId(),vo.getCount());
        return InputDto.data("查询成功",list);
    }
    @PostMapping(value = "/searchItripHotelPage")
    public Dto<Pages<ItripHotelVO>> searchItripHotelPage(@RequestBody SearchHotelVO vo){

            Pages pages=null;
            if (EmptyUtils.isEmpty(vo)||EmptyUtils.isEmpty(vo.getDestination())){
                return InputDto.error("失败");
            }
            try{
                pages=iItripHotelService.searchItripHotelPage(vo,vo.getPageNo(),vo.getPageSize());
            }catch (Exception e){
                e.printStackTrace();
                return InputDto.error("哎");
            }
            return InputDto.data("成功",pages);

    }
}

